package org.example.novelcrawler.util;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.novelcrawler.model.CrawlConfig;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class JSUtil {

    public static List<CrawlConfig> convertJsonStringToObject(ClassPathResource resource) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper(); // Jackson的核心类
        List<CrawlConfig> list=new ArrayList<CrawlConfig>();
        // 方法 2: 先解析为 JsonNode（适合处理复杂结构）
        JsonNode rootNode = objectMapper.readTree(resource.getInputStream());
        if (rootNode.isArray()) {
            for (JsonNode node : rootNode) {
                CrawlConfig config = objectMapper.treeToValue(node, CrawlConfig.class);
                list.add(config);
            }
        }
        return list;
    }

}
